package android.medicalcloud.com.yiapp.yilian.ui.view.adapter;

import android.content.Context;
import android.medicalcloud.com.yiapp.R;
import android.medicalcloud.com.yiapp.yilian.ui.fragment.DateFragment;
import android.medicalcloud.com.yiapp.yilian.ui.fragment.HomeFragment;
import android.medicalcloud.com.yiapp.yilian.ui.fragment.MeFragment;
import android.medicalcloud.com.yiapp.yilian.ui.fragment.OrderFragment;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.CheckBox;


/**
 * Created by yanbo on 16-11-26.
 */
public class MainPagerAdapter extends FragmentPagerAdapter {
    private HomeFragment homeFragment;
    private OrderFragment orderFragment;
    private DateFragment dateFragment;
    private MeFragment meFragment;


    private int[] drawable = {R.drawable.main_tab_home_selector, R.drawable.main_tab_order_selector,
            R.drawable.main_tab_date_selector, R.drawable.main_tab_me_selector};
    private Context context;

    public MainPagerAdapter(FragmentManager fm, Context context) {
        super(fm);
        this.context = context;

    }

    @Override
    public Fragment getItem(int position) {
        switch (position) {
            case 0:
                if (homeFragment == null)
                    homeFragment = HomeFragment.newInstance();
                return homeFragment;
            case 1:
                if (orderFragment == null)
                    orderFragment = OrderFragment.newInstance();
                return orderFragment;
//            case 2:
//                if (conversationFragment == null)
//                    conversationFragment = new ConversationFragment();
//                return conversationFragment;
            case 2:
                if (dateFragment == null)
                    dateFragment =DateFragment.newInstance();
                return dateFragment;
            case 3:
                if (meFragment == null)
                    meFragment = MeFragment.newInstance();
                return meFragment;
        }
        return null;
    }

    @Override
    public int getCount() {
        return 4;
    }

    @Override
    public CharSequence getPageTitle(int position) {
        return null;
    }

    public View getTabView(int position) {
        View view = LayoutInflater.from(context).inflate(R.layout.view_maintablayout_item, null);
        CheckBox checkBox = (CheckBox) view.findViewById(R.id.checkbox);
        checkBox.setButtonDrawable(drawable[position]);

        return view;
    }
}
